package com.content.management.util;

import com.baomidou.mybatisplus.core.toolkit.StringUtils;

import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;

/**
 * @author xinghu
 * @version 1.0
 * @date 2020/4/4 5:19 下午
 */
public final class DateHelper {

	public static final long TEN_MINUTES = 10 * 60 * 1000;
	public static final long ONE_DAY = 24 * 60 * 60 * 1000;

	/**
	 * 日期格式：yyyy-MM-dd
	 */
	public static final String DATE_FORMAT = "yyyy-MM-dd";
	/**
	 * 日期格式：yyyyMMdd
	 */
	public static final String DATE_FORMAT_NO_SPLIT = "yyyyMMdd";
	/**
	 * 日期格式：yyyy-MM-dd HH:mm:ss
	 */
	public static final String DATE_TIME_FORMAT = "yyyy-MM-dd HH:mm:ss";
	/**
	 * 日期格式：yyyy-MM-dd HH:mm:ss.SSS
	 */
	public static final String DATE_TIME_MS_FORMAT = "yyyy-MM-dd HH:mm:ss.SSS";

	public static final DateTimeFormatter DATE_TIME_FORMATTER = DateTimeFormatter.ofPattern(DATE_TIME_FORMAT);

	public static LocalDateTime strToDateTime(String string) {
		return StringUtils.isNotBlank(string) ? LocalDateTime.parse(string, DATE_TIME_FORMATTER) : null;
	}
}
